import 'package:flutter/material.dart';

class GradientBtn extends StatelessWidget {
  double width;
  double height;
  bool disabled;
  List<Color> colors;
  Color color;
  double radius;
  VoidCallback pressed;
  Widget child;
  
  GradientBtn({this.width=76, this.height=24, @required this.child, @required this.pressed, this.disabled = false, this.color, this.colors, this.radius, int colorType}) {
    if(this.width == null) {
      this.width = 22;
    }
    if(this.width == 0) {
      this.width = null;
    }
    if(this.height == null) {
      this.height = 32;
    }
    if(this.radius == null) {
      this.radius = this.height / 2;
    }
    if(this.colors == null) {
      this.colors = [Color.fromARGB(255, 238,195,16), Color.fromARGB(255, 236,153,2), Color.fromARGB(255, 219,98,3)];
      // this.colors = [Color.fromARGB(255, 131,137,141), Color.fromARGB(255, 193,193,193), Color.fromARGB(255, 131,137,141)];
    }
    if(colorType == 2) {
      this.colors = [Color.fromARGB(255, 33,150,243), Color.fromARGB(255, 31,111,229), Color.fromARGB(255, 14,56,230)];
    }
    if(colorType == 3) {
      this.colors = [Color.fromARGB(255, 228,228,228), Color.fromARGB(255, 187,187,187), Color.fromARGB(255, 127,127,127)];
    }
  }
  
  @override
  Widget build(BuildContext context) {
    return Container(
      width: this.width,
      height: this.height,
      child: RaisedButton(
        //让按钮外部轮廓也带圆角
        shape: RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(this.radius))),
        child: Container(
          alignment: Alignment.center,
          decoration: this.color==null ? BoxDecoration(
            gradient: LinearGradient(
              begin: Alignment.topCenter,
              end: Alignment.bottomCenter,
              colors: this.colors),
              borderRadius: BorderRadius.all(Radius.circular(this.radius))
            ) : BoxDecoration(color: color),
          child: this.child
        ),
        onPressed: this.pressed
      ),
    );
  }
}